import requests
import sys
import base64

def download_file(url):
    response = requests.get(url)
    if response.status_code == 200:
        data = response.json()
        if 'content' in data:
            # Decode the content field from Base64
            content = base64.b64decode(data['content'])
            filename = 'url_data.csv'
            with open(filename, 'wb') as f:
                f.write(content)
            print(f"File downloaded: {filename}")
        else:
            print("Error: Content field not found in the response.")
    else:
        print(f"Failed to download file from {url}")

if __name__ == "__main__":
    print("Arguments passed to the script are:", sys.argv)

    if len(sys.argv) != 2:
        print("Usage: python download_csv.py <URL>")
        sys.exit(1)

    url = sys.argv[1]
    download_file(url)
